<?php

App::uses('AppModel', 'Model');

/**
 * Province
 *
 * PHP version 5
 *
 * @category Blocks.Model
 * @package  Croogo
 * @version  1.0
 * @author   Fahad Ibnay Heylaal <contact@fahad19.com>
 * @license  http://www.opensource.org/licenses/mit-license.php The MIT License
 * @link     http://www.croogo.org
 */
class Province extends AppModel {

        public $validate = array(
            'name' => array(
                'rule' => array('minLength', 1),
                'message' => 'Name cannot be empty.',
            ),
            'alias' => array(
                'isUnique' => array(
                    'rule' => 'isUnique',
                    'message' => 'This alias has already been taken.',
                ),
                'minLength' => array(
                    'rule' => array('minLength', 1),
                    'message' => 'Alias cannot be empty.',
                ),
            ),
        );

        /**
         * Filter search fields
         *
         * @var array
         * @access public
         */
        public $filterArgs = array(
            'chooser' => array('type' => null),
            'name' => array('type' => 'like', 'field' => array('Province.name')),
            'province_id' => array('type' => 'value'),
        );

        /**
         * Model associations: belongsTo
         *
         * @var array
         * @access public
         */
        public $belongsTo = array(
            'City' => array(
                'className' => 'City',
                'foreignKey' => 'city_id',
                'counterCache' => true,
                'counterScope' => array('City.status' => 1),
            ),
        );

        /**
         * Display fields for this model
         *
         * @var array
         */
        protected $_displayFields = array(
            'id',
            'name' => array('url' => array('action' => 'edit', 'pass' => 'id')),
            'alias',
            'Province.name' => array('label' => 'Province'),
            'status' => array('type' => 'boolean', 'options' => array('toggle' => true))
        );

     

/**
 * Edit fields for this model
 *
 * @var array
 */
	protected $_editFields = array(
		'name',
                    'alias'=>array('class'=>'span10 slug','slug'=>'name'),
		'province_name'=>array(
                                'label'=>'Quận/Huyện',
                                'chooser'=>array(
                                    'url'=>array('controller'=>'pronvices','action'=>'index'),
                                    'type'=>'Province',
                                    'fields'=>array('field'=>'province_id','select'=>'data-chooser_id'),
                                    'select'=>'data-chooser_field'
                                )),
		'status',
	);               
        
}

?>